<template>
  <el-dialog title="添加" :visible.sync="showDialog" width="40%" @close="close">
    <el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
      <el-form-item label="角色名称" prop="name">
        <el-input v-model="formData.name" />
      </el-form-item>

      <el-form-item label="启用状态">
        <el-switch v-model="formData.state" :inactive-value="0" :active-value="1" />
      </el-form-item>

      <el-form-item label="角色描述" prop="description">
        <el-input v-model="formData.description" />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="showDialog = false">取 消</el-button>
      <el-button type="primary" @click="btnOk">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addRoleApi } from '@/api/role'
export default {
  name: 'AddRole',
  data() {
    return {

      showDialog: false,
      formData: {
        'name': '',
        'description': '',
        'state': 0 // 默认未1启用 关闭 0 打开1
      },
      formRules: {
        name: [{ required: true, message: '请输入角色名称', tigger: 'blur' }],
        description: [{ required: true, message: '请输入角色名称', tigger: 'blur' }]
      }
    }
  },
  methods: {
    async btnOk() {
      await this.$refs.form.validate()
      await addRoleApi(this.formData)
      this.$message.success('添加成功')
      this.showDialog = false
      this.$emit('updataList')
    },
    close() {
      this.formData = {
        'name': '',
        'description': '',
        'state': 0 // 默认未1启用 关闭 0 打开1
      }
      this.$refs.form.clearValidate()
    }

  }
}
</script>

<style scoped>

</style>
